package net.alche.fa.core.model;
import net.alche.al.util.AC;

//
// DebugFall
//
public class DebugFall  {
    Integer  num;
    String  codeStr;
    String  prefix;
    DebugFall  par;
    DebugFall  next;
    Logic  logic;
    String[] firstWhat = new String[] {"switch", "for", "if", "else if", "while", "case","return"};

  public DebugFall (DebugFall  par) {
    this.par = par;
  }

  public void  setLogic(Logic  logic) {
    if ( logic.getNum()!= null) {
      this.num = logic.getNum();
      this.codeStr = logic.getCodeStr();
      this.logic = logic;
    }
  }

  public DebugFall  getPar() {
    return par;
  }

  public void  setPar(DebugFall  par) {
    this.par = par;
  }

  public Integer  getNum() {
    if ( num == null) {
      return null;
    }
    return num + 1;
  }

  public void  setNum(Integer  num) {
    this.num = num;
  }

  public String  getCodeStr() {
    if ( AC .isEmpty(codeStr)&& this.logic != null) {
      return this.getLogicTxt(this.logic);
    }
    return codeStr;
  }

  String  getLogicTxt(Logic  logic) {
    String  txt = "";
    String  what = null;
    String  obj = null;
    String  data = null;
    if ( logic.getWhat()!= null) {
      what = logic.getWhat();
    }
    if ( logic.getObj()!= null) {
      obj = logic.getObj();
    }
    if ( logic.getData()!= null) {
      data = logic.getData();
    }
    if ( logic.getLogicObj()!= null) {
      obj = this.getLogicTxt(logic.getLogicObj());
    }
    if ( logic.getLogicData()!= null) {
      data = this.getLogicTxt(logic.getLogicData());
    }
    boolean  whatFirst = false;
    if ( what != null) {
      for ( String  key: this.firstWhat) {
        if ( key.equals(what)) {
          whatFirst = true;
          break;
        }
      }
      if ( !whatFirst && what.startsWith("var-")) {
        whatFirst = true;
        what = what.substring(4);
      }
    }
    if ( whatFirst) {
      txt += checkTxt(what)+ " ";
    }
    if ( obj != null) {
      txt += checkTxt(obj);
    }
    if ( !whatFirst && what != null) {
      txt += checkTxt(what);
    }
    if ( data != null) {
      txt += checkTxt(data);
    }
    return txt;
  }

  public String  checkTxt(String  txt) {
    if ( txt == null) {
      return "";
    }
    switch ( txt) {
      case "fm-sta" : {
        return "";
      }
      case "(" : {
        return "()";
      }
      case "=" : {
        return " = ";
      }
      case "==" : {
        return " == ";
      }
    }
    return txt;
  }

  public void  setCodeStr(String  codeStr) {
    this.codeStr = codeStr;
  }

  public String  getPrefix() {
    return prefix;
  }

  public void  setPrefix(String  prefix) {
    this.prefix = prefix;
  }

  public DebugFall  getNext() {
    return next;
  }

  public void  setNext(DebugFall  next) {
    this.next = next;
  }
}